/*-------------------------------------------------------------------------------------------------------------------------
	!afk command
-------------------------------------------------------------------------------------------------------------------------*/

local PLUGIN = {}
PLUGIN.Title = "AFK"
PLUGIN.Description = "Show your status as AFK."
PLUGIN.Author = "Matt J"
PLUGIN.ChatCommand = "afk"
PLUGIN.Privileges = { "afk" }
PLUGIN.Usage = ""
function PLUGIN:Call( ply, args )
	local arg = table.concat( args, " " )
	PLUGIN.Messages = { "watching porn",
	"wanking",
	"AFK",
	"thinking of funny lines for this",
	"coming out of the closet",
	"getting some action",
	"giggity giggity gooing",
	"jacking off",
	"becoming a communist",
	"being stalked",
	"being molested",
	"a sexual Panda",
	"dead",
	"unable to move due to requested inactivity",
	"grabbin pills",
	"smoking weed in the basement",
	"wrapping presents",
	"riding santa's sleigh",
	"getting in the back of Matt's van",
	"riding an ostrich",
	"feeding a BBD",
	"a non-moving statue",
	"herding cheese",
	"feeding a chicken",
	"reading the Bible backwards",
	"talking to the cats" }
	if ( ply:EV_HasPrivilege( "afk" ) ) then
		if arg == "nyan" and ply:GetProperty("AFK1") == true then
		evolve:Notify(ply, evolve.colors.white, "You have disabled the ", evolve.colors.red, "default AFK mode", evolve.colors.white, ".")
		ply:SetProperty( "AFK1", false )
		evolve:CommitProperties()
		return;
		elseif arg == "nyan" then
		evolve:Notify(ply, evolve.colors.white, "You have enabled the ", evolve.colors.red, "default AFK mode", evolve.colors.white, ".")
		ply:SetProperty( "AFK1", true )
		evolve:CommitProperties()
		return;
		end
	local r = math.random(1,table.Count(PLUGIN.Messages))
		if(ply:GetProperty("AFK") == true) then
			if(ply:GetProperty("AFK1") == true) then
			evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " is no longer ", evolve.colors.red, "AFK", evolve.colors.white, ".")
			else
			evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " is no longer ", evolve.colors.red, PLUGIN.Messages[r], evolve.colors.white, ".")
			end
		ply:SetProperty( "AFK", false )
		evolve:CommitProperties()
		else
			if(ply:GetProperty("AFK1") == true) then
			evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " is now ", evolve.colors.red, "AFK", evolve.colors.white, ".")
			else
			evolve:Notify(evolve.colors.blue, ply:Nick(), evolve.colors.white, " is now ", evolve.colors.red, PLUGIN.Messages[r], evolve.colors.white, ".")
			end
			
		ply:SetProperty( "AFK", true )
		evolve:CommitProperties()
		end
	else
		evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
	end
end

function PLUGIN:AFKActivate( ply )
	local first = !ply:GetProperty( "LastJoin" )
	
	if ( first ) then
		ply:SetProperty( "AFK", false )
		ply:SetProperty( "AFK1", false )

		evolve:CommitProperties()
	else
		if ( !ply:GetProperty( "AFK" ) ) then ply:SetProperty( "AFK", false ) end
		if ( !ply:GetProperty( "AFK1" ) ) then ply:SetProperty( "AFK1", false ) end
		
		evolve:CommitProperties()
end
end

function PLUGIN:PlayerInitialSpawn( ply )
	ply.EV_AFKInitialize = true
end

function PLUGIN:PlayerSpawn( ply )
	if ( ply.EV_AFKInitialize ) then
		self:AFKActivate( ply )
		ply.EV_AFKInitialize = false
	end
end

evolve:RegisterPlugin( PLUGIN )